]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
iconGrid: Return page and position for drop targets instead of items
authorJonas Dreßler <verdre@v0yd.nl>
Fri, 24 Jun 2022 11:01:16 +0000 (13:01 +0200)
committerMarge Bot <marge-bot@gnome.org>
Wed, 1 Feb 2023 12:56:28 +0000 (12:56 +0000)
Returning a page and a position for the drop target seems more
straightforward than returning an actual grid item in getDropTarget().

With the next commit, this will allow us to throw away drop targets that
are not on the current page.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2348>

js/ui/appDisplay.js
js/ui/iconGrid.js

index 5e9ad63fe0fbaf75eb90310d4dc9511315abf0b2..5008130ad4257c3076f1237334350a53ec026482 100644 (file)
@@ -1172,14 +1172,8 @@ var BaseAppView = GObject.registerClass({
     }
 
     _getDropTarget(x, y, source) {
-        const { currentPage } = this._grid;
-
-        let [item, dragLocation] = this._grid.getDropTarget(x, y);
-
         const [sourcePage, sourcePosition] = this._grid.getItemPosition(source);
-        const targetPage = currentPage;
-        let targetPosition = item
-            ? this._grid.getItemPosition(item)[1] : -1;
+        let [targetPage, targetPosition, dragLocation] = this._grid.getDropTarget(x, y);
 
         // In case we're hovering over the edge of an item but the
         // reflow will happen in the opposite direction (the drag
@@ -1212,14 +1206,6 @@ var BaseAppView = GObject.registerClass({
             }
         }
 
-        // Append to the page if dragging over empty area
-        if (dragLocation === IconGrid.DragLocation.EMPTY_SPACE) {
-            const pageItems =
-                this._grid.getItemsAtPage(currentPage).filter(c => c.visible);
-
-            targetPosition = pageItems.length;
-        }
-
         return [targetPage, targetPosition, dragLocation];
     }
 
index 4e83b56ef9d50d727bc01abccdd09045842a7cba..313621a5e8c4a66605209fdf1792711d8e6c9b59 100644 (file)
@@ -1008,19 +1008,21 @@ var IconGridLayout = GObject.registerClass({
 
         // Out of bounds
         if (page >= this._pages.length)
-            return [null, DragLocation.INVALID];
+            return [0, 0, DragLocation.INVALID];
 
         if (isRtl && this._orientation === Clutter.Orientation.HORIZONTAL)
             page = swap(page, this._pages.length);
 
-        // Page-relative coordinates from now on
+        // Get page-relative coordinates
+        let adjX = x;
+        let adjY = y;
         if (this._orientation === Clutter.Orientation.HORIZONTAL)
-            x %= this._pageWidth;
+            adjX %= this._pageWidth;
         else
-            y %= this._pageHeight;
+            adjY %= this._pageHeight;
 
-        if (x < leftEmptySpace || y < topEmptySpace)
-            return [null, DragLocation.INVALID];
+        if (adjX < leftEmptySpace || adjY < topEmptySpace)
+            return [0, 0, DragLocation.INVALID];
 
         const gridWidth =
             childSize * this.columnsPerPage +
@@ -1029,25 +1031,16 @@ var IconGridLayout = GObject.registerClass({
             childSize * this.rowsPerPage +
             vSpacing * (this.rowsPerPage - 1);
 
-        if (x > leftEmptySpace + gridWidth || y > topEmptySpace + gridHeight)
-            return [null, DragLocation.INVALID];
+        if (adjX > leftEmptySpace + gridWidth || adjY > topEmptySpace + gridHeight)
+            return [0, 0, DragLocation.INVALID];
 
         const halfHSpacing = hSpacing / 2;
         const halfVSpacing = vSpacing / 2;
         const visibleItems = this._pages[page].visibleChildren;
 
-        for (const item of visibleItems) {
-            const childBox = item.allocation.copy();
-
-            // Page offset
-            switch (this._orientation) {
-            case Clutter.Orientation.HORIZONTAL:
-                childBox.set_origin(childBox.x1 % this._pageWidth, childBox.y1);
-                break;
-            case Clutter.Orientation.VERTICAL:
-                childBox.set_origin(childBox.x1, childBox.y1 % this._pageHeight);
-                break;
-            }
+        for (let i = 0; i < visibleItems.length; i++) {
+            const item = visibleItems[i];
+            const childBox = item.allocation;
 
             // Outside the icon boundaries
             if (x < childBox.x1 - halfHSpacing ||
@@ -1072,10 +1065,10 @@ var IconGridLayout = GObject.registerClass({
                     dragLocation = DragLocation.START_EDGE;
             }
 
-            return [item, dragLocation];
+            return [page, i, dragLocation];
         }
 
-        return [null, DragLocation.EMPTY_SPACE];
+        return [page, -1, DragLocation.EMPTY_SPACE];
     }
 
     get iconSize() {